package de.reichelt.fxrequi;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class DialogWindow extends Stage {
  
  private Object data;
  private AnchorPane pane;
  protected int result = 0;
  public int RESULT_UNDEFINED = 0;
  public int RESULT_CANCELLED = 1;
  public int RESULT_OK = 2;
  
  public DialogWindow(String title, String fxmlFile, Object data) {
    super();
    this.data = data;
    try {
      setAlwaysOnTop(true);
      initModality(Modality.APPLICATION_MODAL);
      initOwner(FXrequi.APP.getStage());
      initStyle(StageStyle.UTILITY);
      setTitle(title);
      FXMLLoader ldr = new FXMLLoader(this.getClass().getResource(fxmlFile));
      pane = (AnchorPane)ldr.load();
      Scene scene = new Scene(pane);
      setScene(scene);
      BaseController ctl = (BaseController)ldr.getController();
      ctl.setStage(this);
      ctl.setData(data);
      
    } catch (IOException ex) {
      Logger.getLogger(DialogWindow.class.getName()).log(Level.SEVERE, null, ex);
    }
    
  }

  public DialogWindow(String title, Object data) {
    super();
    this.data = data;
    setAlwaysOnTop(true);
    initModality(Modality.APPLICATION_MODAL);
    initOwner(FXrequi.APP.getStage());
    initStyle(StageStyle.UTILITY);
    setTitle(title);
    pane = new AnchorPane();
    Scene scene = new Scene(pane);
    setScene(scene);
  }
  
  public AnchorPane getPane() {
    return pane;
  }

  public Object getData() {
    return data;
  }

  public void setData(Object data) {
    this.data = data;
  }

  public int getResult() {
    return result;
  }

  public void setResult(int result) {
    this.result = result;
  }
  
  
  
}
